#! /usr/bin/python3
# _*_ coding:UTF-8 _*_
"""
    每次调用countA 返回值递增
    作者：王楠
    备注：廖雪峰 返回函数章节练习
"""


def createCounter():
    count = 0

    def counter():
        nonlocal count
        count += 1
        return count
    return counter


def createCounter1():

    def ger():
        count = 1
        yield count
        while True:
            count += 1
            yield count

    print(ger)
    count_num = ger()
    print(count_num)

    def counter():
        count = next(count_num)
        return count
    return counter


if __name__ == '__main__':
    count1 = createCounter()
    for i in range(10):
        count = count1()
        print(count)
    # 采用生成器实现
    count2 = createCounter1()
    for i in range(10):
        count = count2()
        print(count)
